home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 12.8 KB | 471 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLinShp.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWSHAPE_H
- #include "FWShape.h"
- #endif
-
- #ifndef FWDFAULT_H
- #include "FWDfault.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWARCSHP_H
- #include "FWArcShp.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- //==============================================================================
- // •• RunTime Info
- //==============================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- //==============================================================================
- // •• class FW_CLineShape
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape() :
- FW_CShape()
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CPoint& start, const FW_CPoint& end) :
- FW_CShape()
- {
- SetRep(new FW_CLineShapeRep(start, end));
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
- FW_CShape(other)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(FW_CLineShapeRep* rep) :
- FW_CShape(rep)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator=
- //------------------------------------------------------------------------------
-
- FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
- {
- SetRep(other.GetRep());
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator=
- //------------------------------------------------------------------------------
-
- FW_CLineShape& FW_CLineShape::operator=(FW_CLineShapeRep* other)
- {
- SetRep(other);
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator FW_COvalShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::operator FW_COvalShape() const
- {
- FW_COvalShape ovalShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
- ovalShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return ovalShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator FW_CRoundRectShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::operator FW_CRoundRectShape() const
- {
- FW_CRoundRectShape roundRectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), FW_kZeroPoint);
- roundRectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return roundRectShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator FW_CArcShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::operator FW_CArcShape() const
- {
- FW_CArcShape arcShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), 0, 0);
- arcShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return arcShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator FW_CRectShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::operator FW_CRectShape() const
- {
- FW_CRectShape rectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
- rectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return rectShape;
- }
-
- #ifdef FW_BUILD_MAC
- //-------------------------------------------------------------------------
- // MakeLineRgn
- //-------------------------------------------------------------------------
-
- void MakeLineRgn(FW_SPlatformPoint start, FW_SPlatformPoint end, short pen)
- {
- ::MoveTo(start.h, start.v);
- ::LineTo(end.h, end.v);
- ::Line(pen, 0);
- ::Line(0, pen);
- ::LineTo(start.h + pen, start.v + pen);
- ::Line(-pen, 0);
- ::Line(0, -pen);
- }
- #endif
-
- //------------------------------------------------------------------------------
- // FW_CLineShape::operator FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CLineShape::operator FW_CRegionShape() const
- {
- #ifdef FW_BUILD_MAC
- FW_CPoint endPoint = ((FW_CLineShapeRep*)GetRep())->GetLineEnd();
- FW_CPoint startPoint = ((FW_CLineShapeRep*)GetRep())->GetLineStart();
- FW_SPlatformPoint start = startPoint;
- FW_SPlatformPoint end = endPoint;
- short pen = 1;
-
- ::OpenRgn();
-
- if (endPoint.x < startPoint.x)
- {
- if (endPoint.y < startPoint.y)
- {
- ::MoveTo(start.h + pen, start.v);
- ::LineTo(end.h + pen, end.v);
- ::Line(-pen, 0);
- ::Line(0, pen);
- ::LineTo(start.h, start.v + pen);
- ::Line(-pen, 0);
- ::Line(0, -pen);
- }
- else if (endPoint.y > startPoint.y)
- {
- ::MakeLineRgn(start, end, pen);
- }
- else
- {
- ::MakeLineRgn(start, end, pen);
- }
- }
- else if (endPoint.x > startPoint.x)
- {
- if (endPoint.y < startPoint.y)
- {
- ::MakeLineRgn(start, end, pen);
- }
- else if (endPoint.y > startPoint.y)
- {
- ::MoveTo(start.h, start.v);
- ::Line(pen, 0);
- ::LineTo(end.h + pen, end.v);
- ::Line(0, pen);
- ::Line(-pen, 0);
- ::LineTo(start.h, start.v + pen);
- ::Line(0, -pen);
- }
- else
- {
- ::MakeLineRgn(start, end, pen);
- }
- }
- else
- {
- if (endPoint.y < startPoint.y)
- {
- ::MakeLineRgn(start, end, pen);
- }
- else if (endPoint.y > startPoint.y)
- {
- ::MakeLineRgn(start, end, pen);
- }
- else
- {
- ::MoveTo(start.h, start.v);
- ::Line(pen, 0);
- ::Line(0, pen);
- ::Line(-pen, 0);
- ::Line(0, -pen);
- }
- }
- FW_PlatformRegion rgn = ::NewRgn();
- ::CloseRgn(rgn);
-
- XMPShape* xmpShape = ::NewXMPShape(rgn);
- FW_CRegionShape regionShape(xmpShape);
- return regionShape;
- #endif
- #ifdef FW_BUILD_WIN
- NotYetImplemted();
- #endif
- }
-
- //==============================================================================
- // •• class FW_CLineShapeRep
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::FW_CLineShapeRep
- //------------------------------------------------------------------------------
-
- FW_CLineShapeRep::FW_CLineShapeRep() :
- FW_CShapeRep(gGraphicGlobales.gLine),
- fStart(FW_kZeroPoint),
- fEnd(FW_kZeroPoint)
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::FW_CLineShapeRep
- //------------------------------------------------------------------------------
-
- FW_CLineShapeRep::FW_CLineShapeRep(const FW_CPoint& start, const FW_CPoint& end) :
- FW_CShapeRep(gGraphicGlobales.gLine),
- fStart(start),
- fEnd(end)
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::~FW_CLineShapeRep
- //------------------------------------------------------------------------------
-
- FW_CLineShapeRep::~FW_CLineShapeRep()
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::Draw
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::Draw(FW_CGraphicContext* graphicContext)
- {
- FW_ShapeFills shapeFill = GetShapeFill();
-
- if (shapeFill == FW_kNullShape)
- return;
-
- graphicContext->SelectInkAndStyle(GetShapeInk(), GetShapeStyle(), FW_kGeometricShape, shapeFill);
-
- FW_SPlatformPoint start = graphicContext->AsPlatformPoint(fStart);
- FW_SPlatformPoint end = graphicContext->AsPlatformPoint(fEnd);
-
- #ifdef FW_BUILD_MAC
- ::MoveTo(start.h, start.v);
- ::LineTo(end.h, end.v);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::DrawLine
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::DrawLine(FW_CGraphicContext* graphicContext,
- const FW_CPoint& start,
- const FW_CPoint& end)
- {
- if (gGraphicGlobales.gLine.fFill == FW_kNullShape)
- return;
-
- graphicContext->SelectInkAndStyle(gGraphicGlobales.gLine.fInk, gGraphicGlobales.gLine.fStyle, FW_kGeometricShape, gGraphicGlobales.gLine.fFill);
-
- FW_SPlatformPoint qdStart = graphicContext->AsPlatformPoint(start);
- FW_SPlatformPoint qdEnd = graphicContext->AsPlatformPoint(end);
-
- #ifdef FW_BUILD_MAC
- ::MoveTo(qdStart.h, qdStart.v);
- ::LineTo(qdEnd.h, qdEnd.v);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::GetShapeBounds
- //------------------------------------------------------------------------------
-
- FW_CRect FW_CLineShapeRep::GetShapeBounds() const
- {
- FW_CRect bounds;
-
- XMPCoordinate penSize = GetShapeStyle()->GetPenSize();
-
- bounds.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
- bounds.Sort();
- bounds.right += penSize;
- bounds.bottom += penSize;
-
- return bounds;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::Transform
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::Transform(XMPTransform* transform)
- {
- fStart = transform->TransformPoint(fStart);
- fEnd = transform->TransformPoint(fEnd);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::InverseTransform
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::InverseTransform(XMPTransform* transform)
- {
- fStart = transform->InvertPoint(fStart);
- fEnd = transform->InvertPoint(fEnd);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::MoveShape
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY)
- {
- fStart.x += deltaX;
- fStart.y += deltaY;
- fEnd.x += deltaX;
- fEnd.y += deltaY;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::MoveShapeTo
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::MoveShapeTo(XMPCoordinate x, XMPCoordinate y)
- {
- fEnd.x += x - fStart.x;
- fEnd.y += y - fStart.y;
- fStart.x = x;
- fStart.y = y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::Copy
- //------------------------------------------------------------------------------
-
- FW_CLineShape FW_CLineShapeRep::Copy() const
- {
- FW_CLineShape line(fStart, fEnd);
- return line;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::SetAsDefault
- //------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::SetAsDefault() const
- {
- SetDefaultProperties(gGraphicGlobales.gLine);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CLineShapeRep::HitTest
- //------------------------------------------------------------------------------
-
- FW_HitTestPart FW_CLineShapeRep::HitTest(const FW_CPoint& test) const
- {
- return FW_kOutside;
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CLineShapeRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::Flatten(FW_CWritableStream& stream)
- {
- fStart.Flatten(stream);
- fEnd.Flatten(stream);
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CLineShapeRep::Unflatten
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShapeRep::Unflatten(FW_CReadableStream& stream)
- {
- fStart.Unflatten(stream);
- fEnd.Unflatten(stream);
- }
-